﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace Yipusoft.SystemSet
{
    public class Func
    {
        public static string GetItem(string key,string name)
        {
            string registData;
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey productDir = software.OpenSubKey(key, true);
            registData =productDir.GetValue(name)!=null? productDir.GetValue(name).ToString():"";
            return registData;
        }

        public static void WriteItem(string key,string name, string tovalue)
        {
            RegistryKey hklm = Registry.LocalMachine;
            RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
            RegistryKey productDir = software.OpenSubKey(key, true);
            productDir.SetValue(name, tovalue);
        }

        public static void DeleteItem(string key,string name)
        {
            string[] aimnames;
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey productDir = software.OpenSubKey(key, true);
            aimnames = productDir.GetSubKeyNames();
            foreach (string aimKey in aimnames)
            {
                if (aimKey == name)
                    productDir.DeleteSubKeyTree(name);
            }
        }
    }
}
